package com.hfuu.demo.component;

import com.hfuu.demo.domain.model.LoginUser;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;

/**
 * @description:
 * @author: gunala
 * @date: 2024/2/6 15:57
 */
@Component("securityAuthority")
public class SecurityAuthority {

    public boolean hasAuthority(String authority){
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        LoginUser loginUser =(LoginUser) authentication.getPrincipal();
        return loginUser.getPermissions().contains(authority);
    }
}
